import wx


class RoundButton(wx.Panel):
    def __init__(self, parent, size,  name=None, label=None, font_size=None, weight=None, fg=None, bg=None):
        super(RoundButton, self).__init__(parent, size=size, name=name)

        self.label = label
        self.background_color = bg if bg else (37, 188, 189)
        self.font_size = font_size if font_size else 10
        self.font_color = fg if fg else (255, 255, 255)
        self.weight = weight if weight else wx.FONTWEIGHT_NORMAL

        self.Bind(wx.EVT_PAINT, self.on_paint)

        self.clicked = False
        self.hovered = False

    def on_paint(self, event):
        dc = wx.BufferedPaintDC(self)
        dc.Clear()
        gc = wx.GraphicsContext.Create(dc)
        gc.SetAntialiasMode(wx.ANTIALIAS_DEFAULT)

        gc.SetBrush(wx.Brush(wx.Colour(self.background_color)))
        gc.SetPen(wx.TRANSPARENT_PEN)
        gc.DrawRoundedRectangle(0, 0, self.GetSize().width, self.GetSize().height, 10)

        # 设置文本颜色和字体
        text_color = wx.Colour("#FFFFFF")  # 文本颜色
        text_font = wx.Font(self.font_size, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, self.weight, faceName="微软雅黑")
        gc.SetFont(font=text_font, colour=text_color)
        text_width, text_height = gc.GetTextExtent(self.label)
        x = (self.GetSize().width - text_width) / 2
        y = (self.GetSize().height - text_height) / 2
        gc.DrawText(self.label, x, y)

    def set_label(self, label):
        self.label = label

    def set_background(self, colour):
        self.background_color = colour
